import keyMirror from 'keymirror';

const userState = keyMirror({
    NOT_LOGINED: null,
    LOGINED: null
});

const initialState = {
    loginState: 'LOGINED',
    session: {
        userid: window.sessionStorage.getItem('userid') ? window.sessionStorage.getItem('userid') : '',
        username: window.sessionStorage.getItem('nickname') ? window.sessionStorage.getItem('nickname') : '',
    }
};

const reducer = function (state, action) {
    if (typeof state === 'undefined') state = initialState;
    switch (action.type) {
        case 'LOGINED':
            return { 
                session: {
                    userid: window.sessionStorage.getItem('userid'),
                    username: window.sessionStorage.getItem('nickname'),
                }
            }; 
            // 
        default:
            return state;
    }
}
// 
export {
    reducer as default,
    initialState as userStateInitialState,
    userState
};
